const send = require('send');
const path = require('path');

function createStaticProxy(dirPath, option = {}) {
	const root = path.resolve(dirPath);
	console.log('root-createStaticProxy',root);
	return (req, res, next, filePath = req.originalUrl) => {
		if (filePath.endsWith('/')) return next();
		const stream = send(req, filePath, {root, index: [], ...option});
		stream.on('directory', next);
		stream.on('error', next);
		stream.pipe(res);
	};
}


module.exports = {
	createStaticProxy
}